//
//  MineListCell.m
//  JPWords
//
//  Created by 梁淑婷 on 2024/5/24.
//

#import "MineListCell.h"

@interface MineListCell()
@property(nonatomic,strong)UIImageView *logoImageView;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *tipLabel;
@property(nonatomic,strong)UIView *bgView;
@end

@implementation MineListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    CGFloat currentAvailableWidth = [DeviceUtils currentAvailableWidth];
    
    self.backgroundColor = [UIColor clearColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.bgView = [[UIView alloc]initWithFrame:CGRectMake(16,0,currentAvailableWidth-32,61)];
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.bgView];
    
    __weak typeof(self)self_weak_ = self;
    self.logoImageView = [[UIImageView alloc]init];
    [self.bgView addSubview:self.logoImageView];
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@16);
        make.width.height.mas_equalTo(@18);
        make.centerY.mas_equalTo(self_weak_.bgView);
    }];
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.font = JPUIFontPingFangSCMedium(15);
    self.titleLabel.textColor = KFontBlackColor;
    [self.bgView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self_weak_.logoImageView.mas_right).offset(12);
        make.height.mas_equalTo(@20);
        make.centerY.mas_equalTo(self_weak_.bgView);
    }];
    
    UIImageView *arrowImageView = [[UIImageView alloc]init];
    arrowImageView.image = [UIImage imageNamed:@"mine_right_arrow"];
    [self.bgView addSubview:arrowImageView];
    [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(@16);
        make.right.mas_equalTo(@-16);
        make.centerY.mas_equalTo(self_weak_.bgView);
    }];
    
    self.tipLabel = [[UILabel alloc]init];
    self.tipLabel.font = JPUIFontPingFangSCRegular(14);
    self.tipLabel.textColor = KFontGrayColor;
    self.tipLabel.text = @"一起来背单词吧！";
    [self.bgView addSubview:self.tipLabel];
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(@-38);
        make.height.mas_equalTo(@20);
        make.centerY.mas_equalTo(self_weak_.bgView);
    }];
    self.tipLabel.hidden = YES;
    
}

-(void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
    if([title isEqualToString:@"邀请好友"]){
        self.tipLabel.text = @"一起来背单词吧！";
        self.tipLabel.hidden = NO;
    }else{
        self.tipLabel.hidden = YES;
    }
    if(isIPAD){
        if(self.currentAvailableWidth != (self.bgView.width+32)){
            self.bgView.frame =  CGRectMake(16,0,self.currentAvailableWidth-32,61);
        }
    }
}

-(void)setImage:(NSString *)image{
    _image = image;
    self.logoImageView.image = [UIImage imageNamed:image];
}

-(void)refreshWithRow:(NSInteger)row andCount:(NSInteger)count{
    if(count == 1){
        [self.bgView addRoundedCorners:UIRectCornerAllCorners withRadii:CGSizeMake(10,10)];
    }else{
        if(row == 0){
            [self.bgView addRoundedCorners:UIRectCornerTopLeft|UIRectCornerTopRight withRadii:CGSizeMake(10,10)];
        }else if (row == count-1){
            [self.bgView addRoundedCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight withRadii:CGSizeMake(10,10)];
        }else{
            [self.bgView addRoundedCorners:UIRectCornerAllCorners withRadii:CGSizeMake(0,0)];
        }
    }
}




@end
